package com.ss.android.article.base.feature.search;

import android.content.res.Resources;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import com.ss.android.account.b.OnAccountRefreshListener;
import com.ss.android.account.Spipe;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.app.a.ArticleConstants;
import com.ss.android.article.base.feature.app.browser.GetEntryItemHelper;
import com.ss.android.article.browser.R;
import com.ss.android.common.app.AbsFragment;
import com.ss.android.newmedia.util.AppUtil;

public final class m extends AbsFragment implements OnAccountRefreshListener {
    GetEntryItemHelper a;
    private ImageView b;
    private ImageView c;
    private ImageView d;
    private TextView e;
    private FrameLayout f;
    private View g;
    private View h;
    private boolean i;
    private boolean j;
    private Spipe k;

    public m() {

        this.i = false;
        this.j = false;
    }

    private static String a() {
        String v0 = !android.support.design.a.isTextEmpty(AppData.getInstance().discoverUrl) ? AppData.getInstance().discoverUrl : ArticleConstants.discoverWapDiscoverPageUrl;
        StringBuilder v1 = new StringBuilder(v0);
        AppUtil.a(v1);
        v0 = v1.indexOf("#") > 0 ? "&" : "#";
        v1.append(v0);
        StringBuilder v2 = v1.append("tt_daymode=");
        AppData.getInstance();
        char v0_1 = AppData.isNightMode() ? '0' : '1';
        v2.append(v0_1);
        return v1.toString();
    }

    public final void onAccountRefresh(boolean arg4, int arg5) {
        if(this.a != null) {
            this.a.a(m.a(), false);
        }
    }

    public final void onActivityCreated(Bundle arg3) {
        super.onActivityCreated(arg3);
        this.b.setOnClickListener(new n(this));
        this.c.setOnClickListener(new o(this));
    }

    public final View onCreateView(LayoutInflater arg13, ViewGroup arg14, Bundle arg15) {
        long v10 = 1000;
        int v9 = R.id.mo;
        View v2 = arg13.inflate(com.ss.android.article.browser.R.layout.b7, arg14, false);
        this.k = Spipe.inst();
        Bundle v0 = this.getArguments();
        if(v0 != null) {
            this.i = v0.getBoolean("new_arch", false);
        }

        this.g = v2.findViewById(com.ss.android.article.browser.R.id.mn);
        this.h = v2.findViewById(com.ss.android.article.browser.R.id.mm);
        this.b = v2.findViewById(com.ss.android.article.browser.R.id.mj);
        this.c = v2.findViewById(com.ss.android.article.browser.R.id.mi);
        ImageView v3 = this.c;
        int v0_1 = this.i ? View.GONE : View.VISIBLE;
        v3.setVisibility(v0_1);
        this.e = v2.findViewById(com.ss.android.article.browser.R.id.mk);
        this.d = v2.findViewById(com.ss.android.article.browser.R.id.ml);
        this.f = v2.findViewById(v9);
        View v3_1 = this.g;
        Resources v4 = this.getResources();
        v0_1 = this.i ? R.color.if0 : R.color.ih;
        v3_1.setBackgroundColor(v4.getColor(v0_1));
        v3 = this.b;
        v0_1 = this.i ? R.drawable.av : R.drawable.base_discover_old_input;
        v3.setBackgroundResource(v0_1);
        if(this.f != null) {
            this.a = new GetEntryItemHelper();
            v0 = new Bundle();
            v0.putString("bundle_url", m.a());
            v0.putBoolean("bundle_use_day_night", true);
            if(!this.i) {
                AppData v3_2 = AppData.getInstance();
                if(System.currentTimeMillis() / v10 - v3_2.discoverPageLastRefreshTime < v3_2.discoverPageRefreshSeconds) {
                    v0.putBoolean("bundle_enable_app_cache", true);
                }
                else {
                    v0.putBoolean("bundle_enable_app_cache", false);
                    v3_2.discoverPageLastRefreshTime = System.currentTimeMillis() / v10;
                }
            }

            this.a.setArguments(v0);
            this.getFragmentManager().beginTransaction().add(v9, this.a, "browser_fragment").commitAllowingStateLoss();
        }

        this.k.addOnAccountRefreshListener(((OnAccountRefreshListener)this));
        return v2;
    }

    public final void onDestroyView() {
        super.onDestroyView();
        this.k.b(((OnAccountRefreshListener)this));
    }

    public final void onResume() {
        super.onResume();
        if(this.isViewValid()) {
            boolean v0 = this.j;
            AppData.getInstance();
            if(v0 != AppData.isNightMode()) {
                AppData.getInstance();
                this.j = AppData.isNightMode();
                if(this.i) {
                    this.g.setBackgroundColor(this.getResources().getColor(com.ss.android.article.browser.R.color.if0));
                    this.b.setBackgroundResource(com.ss.android.article.browser.R.drawable.av);
                }
                else {
                    this.g.setBackgroundColor(this.getResources().getColor(com.ss.android.article.browser.R.color.ih));
                    this.b.setBackgroundResource(com.ss.android.article.browser.R.drawable.base_discover_old_input);
                }

                this.h.setBackgroundColor(this.getResources().getColor(com.ss.android.article.browser.R.color.id));
                this.c.setImageResource(com.ss.android.article.browser.R.drawable.btn_back);
                this.e.setTextColor(this.getResources().getColor(com.ss.android.article.browser.R.color.ib));
                this.d.setImageResource(com.ss.android.article.browser.R.drawable.search_discover_normal);
                if(this.a == null) {
                    return;
                }

                StringBuilder v1 = new StringBuilder("javascript:TouTiao.setDayMode(");
                char v0_1 = this.j ? '0' : '1';
                this.a.a(v1.append(v0_1).append(")").toString(), false);
            }
        }
    }
}

